﻿using System;
using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using UBlockly;
using UBlockly.Compotent;
using UBlockly.Graphic;
using UnityEngine;
using UBlockly.Scriptable;

class DefaultSizeData
{
    const int BlockDescFontSize = 26; //块描述字体大小
    const int ParamFontSize = 22; //参数字体大小
    const int DescHeight = 60; //文字高度
    const int BlockDescMinWidth = 80; //块描述文字最小宽度
    const float BlockDescMaxWidth = 300; //块描述最大长度
    const float PackerDescMaxWidth = 120; //参数描述最大长度
    const float PackerDescMinWidth = 60; //参数描述最小宽度
    const float SlotRect_X = 140;
    const float SlotRect_Y = 50; //槽碰撞区域
    const float LeftBorderSpan = 26; //左边界距离 
    const float RightBorderSpan = 16; //右边界距离
    const float BlockDescPackerSpace = 20; //块描述与参数间距
    const float PackerLeftBorderSpace = 2; //参数左边距
    const float PackerDescComponentSpace = 15; //参数描述与组件间距
    const float PackerComponentBorder = 2f; //参数内组件的边界
    const float PackerComponentMinHeight = 60; //参数内组件最小高度
    const float PackerCompnentMinWidth = 110; //参数内组件最小长度
    const float PackerBlockBorder = 4f; //参数内组件
    const float BlockMinLength = 120f; //块最小长度
    const float BlockMinHeight = PackerBlockBorder * 2 + PackerComponentMinHeight + PackerComponentBorder * 2;
    const float VoidRBlockOffset = 20; //空类型的块长度 
}

public static class GraphicHelper
{
    private static BlockResource blockRes;

    internal static BlockResource Graphic => blockRes;

    internal static void InitGraphic(BlockResource res)
    {
        blockRes = res;
    }

    internal static ColorDefine ToColorDefine(string returnTypeStr)
    {
        return (ColorDefine) Enum.Parse(typeof(ColorDefine), $"{returnTypeStr}TypeNode");
    }

    internal static SpriteDefine ToSpriteDefine(string returnTypeStr)
    {
        return (SpriteDefine) Enum.Parse(typeof(SpriteDefine), $"{returnTypeStr}TypeNode");
    }
    internal static GetterDefine ToGetterDefine(string returnTypeStr)
    {
        return (GetterDefine) Enum.Parse(typeof(GetterDefine), $"{returnTypeStr}TypeNode");
    }

    internal static SetterDefine ToSetterDefine(string returnTypeStr)
    {
        return (SetterDefine) Enum.Parse(typeof(SetterDefine), $"{returnTypeStr}TypePanel");
    }
}
public static class BlockGraphicSize
{
    public static readonly int BlockDescFontSize = (int)GraphicHelper.Graphic.GetSize(SizeDefine.BlockDescFont.ToString());
    public static readonly int ParamFontSize =
        (int) GraphicHelper.Graphic.GetSize(SizeDefine.ParamFontSize.ToString());

    static float GetSize(SizeDefine key)
    {
        return GraphicHelper.Graphic.GetSize(key.ToString());
    }
    public static readonly int DescHeight = (int) GetSize(SizeDefine.DescHeight);
    public static readonly int BlockDescMinWidth = (int) GetSize(SizeDefine.BlockDescMinWidth);           
    public static readonly float BlockDescMaxWidth =  GetSize(SizeDefine.BlockDescMaxWidth); 
    public static readonly float PackerDescMaxWidth =  GetSize(SizeDefine.PackerDescMaxWidth); 
    public static readonly float PackerDescMinWidth = GetSize(SizeDefine.PackerDescMinWidth); 
    public static readonly Vector2 SlotRect = new Vector2(GetSize(SizeDefine.SlotRect_X),GetSize(SizeDefine.SlotRect_Y)); 
    public static readonly float LeftBorderSpan =  GetSize(SizeDefine.LeftBorderSpan); 
    public static readonly float RightBorderSpan =  GetSize(SizeDefine.RightBorderSpan); 
    public static readonly float BlockDescPackerSpace =  GetSize(SizeDefine.BlockDescPackerSpace); 
    public static readonly float PackerLeftBorderSpace =  GetSize(SizeDefine.PackerLeftBorderSpace); 
    public static readonly float PackerDescComponentSpace =  GetSize(SizeDefine.PackerDescComponentSpace); 
    public static readonly float PackerComponentBorder = GetSize(SizeDefine.PackerComponentBorder); 
    public static readonly float PackerComponentMinHeight = (int) GetSize(SizeDefine.PackerComponentMinHeight); 
    public static readonly float PackerCompnentMinWidth = (int) GetSize(SizeDefine.PackerCompnentMinWidth); 
    public static readonly float PackerBlockBorder = (int) GetSize(SizeDefine.PackerBlockBorder); 
    public static readonly float BlockMinLength = (int) GetSize(SizeDefine.BlockMinLength); 
    public static readonly float BlockMinHeight = PackerBlockBorder * 2 + PackerComponentMinHeight + PackerComponentBorder * 2;
    public static readonly float VoidRBlockOffset =(int) GetSize(SizeDefine.VoidRBlockOffset);

    public static readonly float BlockVertialSpace = -6f;
    public static readonly float VoidRContentVOffset = 4.5f;
}
public static class BlockGraphicColor
{
    public static Color GetColor(ColorDefine key)
    {
        return GraphicHelper.Graphic.GetColor(key.ToString()); 
    }
    
    public static Color VoidRTypeNode= GetColor(ColorDefine.VoidRTypeNode);
    public static Color VoidR1TypeNode= GetColor(ColorDefine.VoidR1TypeNode);
    public static Color VoidR2TypeNode = GetColor(ColorDefine.NodeDesc);

    public static Color BoolRTypeNode= GetColor(ColorDefine.BoolRTypeNode);
    public static Color BoolR1TypeNode= GetColor(ColorDefine.BoolR1TypeNode);
    public static Color BoolR2TypeNode= GetColor(ColorDefine.BoolR2TypeNode);
    public static Color BoolR3TypeNode= GetColor(ColorDefine.BoolR3TypeNode);
    public static Color BoolR4TypeNode= GetColor(ColorDefine.BoolR4TypeNode);
    public static Color BoolR5TypeNode= GetColor(ColorDefine.BoolR5TypeNode);
    public static Color BoolR6TypeNode= GetColor(ColorDefine.BoolR6TypeNode);
    public static Color BoolR7TypeNode= GetColor(ColorDefine.BoolR7TypeNode);
    public static Color BoolR8TypeNode= GetColor(ColorDefine.BoolR8TypeNode);
    public static Color BoolR9TypeNode= GetColor(ColorDefine.BoolR9TypeNode);
    
    public static Color IntRTypeNode= GetColor(ColorDefine.IntRTypeNode);
    public static Color IntR1TypeNode= GetColor(ColorDefine.IntR1TypeNode);
    public static Color IntR2TypeNode= GetColor(ColorDefine.IntR2TypeNode);
    public static Color IntR3TypeNode= GetColor(ColorDefine.IntR3TypeNode);
    public static Color IntR4TypeNode= GetColor(ColorDefine.IntR4TypeNode);
    public static Color IntR5TypeNode= GetColor(ColorDefine.IntR5TypeNode);
    public static Color IntR6TypeNode= GetColor(ColorDefine.IntR6TypeNode);
    public static Color IntR7TypeNode= GetColor(ColorDefine.IntR7TypeNode);
    public static Color IntR8TypeNode= GetColor(ColorDefine.IntR8TypeNode);
    public static Color IntR9TypeNode= GetColor(ColorDefine.IntR9TypeNode);
         
    public static Color StringRTypeNode= GetColor(ColorDefine.StringRTypeNode);
    public static Color StringR1TypeNode= GetColor(ColorDefine.StringR1TypeNode);
    public static Color StringR2TypeNode= GetColor(ColorDefine.StringR2TypeNode);
    public static Color StringR3TypeNode= GetColor(ColorDefine.StringR3TypeNode);
    public static Color StringR4TypeNode= GetColor(ColorDefine.StringR4TypeNode);
    public static Color StringR5TypeNode= GetColor(ColorDefine.StringR5TypeNode);
    public static Color StringR6TypeNode= GetColor(ColorDefine.StringR6TypeNode);
    public static Color StringR7TypeNode= GetColor(ColorDefine.StringR7TypeNode);
    public static Color StringR8TypeNode= GetColor(ColorDefine.StringR8TypeNode);
    public static Color StringR9TypeNode= GetColor(ColorDefine.StringR9TypeNode);
 
    public static Color FloatRTypeNode= GetColor(ColorDefine.FloatRTypeNode);
    public static Color FloatR1TypeNode= GetColor(ColorDefine.FloatR1TypeNode);
    public static Color FloatR2TypeNode= GetColor(ColorDefine.FloatR2TypeNode);
    public static Color FloatR3TypeNode= GetColor(ColorDefine.FloatR3TypeNode);
    public static Color FloatR4TypeNode= GetColor(ColorDefine.FloatR4TypeNode);
    public static Color FloatR5TypeNode= GetColor(ColorDefine.FloatR5TypeNode);
    public static Color FloatR6TypeNode= GetColor(ColorDefine.FloatR6TypeNode);
    public static Color FloatR7TypeNode= GetColor(ColorDefine.FloatR7TypeNode);
    public static Color FloatR8TypeNode= GetColor(ColorDefine.FloatR8TypeNode);
    public static Color FloatR9TypeNode= GetColor(ColorDefine.FloatR9TypeNode);
         
    public static Color EnumRTypeNode= GetColor(ColorDefine.EnumRTypeNode);
    public static Color EnumR1TypeNode= GetColor(ColorDefine.EnumR1TypeNode);
    public static Color EnumR2TypeNode= GetColor(ColorDefine.EnumR2TypeNode);
    public static Color EnumR3TypeNode= GetColor(ColorDefine.EnumR3TypeNode);
    public static Color EnumR4TypeNode= GetColor(ColorDefine.EnumR4TypeNode);
    public static Color EnumR5TypeNode= GetColor(ColorDefine.EnumR5TypeNode);
    public static Color EnumR6TypeNode= GetColor(ColorDefine.EnumR6TypeNode);
    public static Color EnumR7TypeNode= GetColor(ColorDefine.EnumR7TypeNode);
    public static Color EnumR8TypeNode= GetColor(ColorDefine.EnumR8TypeNode);
    public static Color EnumR9TypeNode= GetColor(ColorDefine.EnumR9TypeNode);
         
    public static Color NodeDesc= GetColor(ColorDefine.NodeDesc);
    public static Color NodeParamDesc= GetColor(ColorDefine.NodeParamDesc);
}

public static class BlockGraphicSprite
{ 
    public static Sprite GetSprite(SpriteDefine key)
    {
        return GraphicHelper.Graphic.GetSprite(key.ToString());
    }
    
//    public static Sprite VoidRTypeNode= GetSprite(SpriteDefine.VoidRTypeNode);
//    public static Sprite VoidR1TypeNode= GetSprite(SpriteDefine.VoidR1TypeNode);
//    public static Sprite VoidR2TypeNode= GetSprite(SpriteDefine.VoidR2TypeNode);
//    public static Sprite VoidR3TypeNode= GetSprite(SpriteDefine.VoidR3TypeNode);
//    public static Sprite VoidR4TypeNode= GetSprite(SpriteDefine.VoidR4TypeNode);
//    public static Sprite VoidR5TypeNode= GetSprite(SpriteDefine.VoidR5TypeNode);
//    public static Sprite VoidR6TypeNode= GetSprite(SpriteDefine.VoidR6TypeNode);
//    public static Sprite VoidR7TypeNode= GetSprite(SpriteDefine.VoidR7TypeNode);
//    public static Sprite VoidR8TypeNode= GetSprite(SpriteDefine.VoidR8TypeNode);
//    public static Sprite VoidR9TypeNode= GetSprite(SpriteDefine.VoidR9TypeNode);
//    public static Sprite BoolRTypeNode= GetSprite(SpriteDefine.BoolRTypeNode);
//    public static Sprite BoolR1TypeNode= GetSprite(SpriteDefine.BoolR1TypeNode);
//    public static Sprite BoolR2TypeNode= GetSprite(SpriteDefine.BoolR2TypeNode);
//    public static Sprite BoolR3TypeNode= GetSprite(SpriteDefine.BoolR3TypeNode);
//    public static Sprite BoolR4TypeNode= GetSprite(SpriteDefine.BoolR4TypeNode);
//    public static Sprite BoolR5TypeNode= GetSprite(SpriteDefine.BoolR5TypeNode);
//    public static Sprite BoolR6TypeNode= GetSprite(SpriteDefine.BoolR6TypeNode);
//    public static Sprite BoolR7TypeNode= GetSprite(SpriteDefine.BoolR7TypeNode);
//    public static Sprite BoolR8TypeNode= GetSprite(SpriteDefine.BoolR8TypeNode);
//    public static Sprite BoolR9TypeNode= GetSprite(SpriteDefine.BoolR9TypeNode);
//    public static Sprite IntRTypeNode= GetSprite(SpriteDefine.IntRTypeNode);
//    public static Sprite IntR1TypeNode= GetSprite(SpriteDefine.IntR1TypeNode);
//    public static Sprite IntR2TypeNode= GetSprite(SpriteDefine.IntR2TypeNode);
//    public static Sprite IntR3TypeNode= GetSprite(SpriteDefine.IntR3TypeNode);
//    public static Sprite IntR4TypeNode= GetSprite(SpriteDefine.IntR4TypeNode);
//    public static Sprite IntR5TypeNode= GetSprite(SpriteDefine.IntR5TypeNode);
//    public static Sprite IntR6TypeNode= GetSprite(SpriteDefine.IntR6TypeNode);
//    public static Sprite IntR7TypeNode= GetSprite(SpriteDefine.IntR7TypeNode);
//    public static Sprite IntR8TypeNode= GetSprite(SpriteDefine.IntR8TypeNode);
//    public static Sprite IntR9TypeNode= GetSprite(SpriteDefine.IntR9TypeNode);
//    public static Sprite StringRTypeNode= GetSprite(SpriteDefine.StringRTypeNode);
//    public static Sprite StringR1TypeNode= GetSprite(SpriteDefine.StringR1TypeNode);
//    public static Sprite StringR2TypeNode= GetSprite(SpriteDefine.StringR2TypeNode);
//    public static Sprite StringR3TypeNode= GetSprite(SpriteDefine.StringR3TypeNode);
//    public static Sprite StringR4TypeNode= GetSprite(SpriteDefine.StringR4TypeNode);
//    public static Sprite StringR5TypeNode= GetSprite(SpriteDefine.StringR5TypeNode);
//    public static Sprite StringR6TypeNode= GetSprite(SpriteDefine.StringR6TypeNode);
//    public static Sprite StringR7TypeNode= GetSprite(SpriteDefine.StringR7TypeNode);
//    public static Sprite StringR8TypeNode= GetSprite(SpriteDefine.StringR8TypeNode);
//    public static Sprite StringR9TypeNode= GetSprite(SpriteDefine.StringR9TypeNode);
//    public static Sprite FloatRTypeNode= GetSprite(SpriteDefine.FloatRTypeNode);
//    public static Sprite FloatR1TypeNode= GetSprite(SpriteDefine.FloatR1TypeNode);
//    public static Sprite FloatR2TypeNode= GetSprite(SpriteDefine.FloatR2TypeNode);
//    public static Sprite FloatR3TypeNode= GetSprite(SpriteDefine.FloatR3TypeNode);
//    public static Sprite FloatR4TypeNode= GetSprite(SpriteDefine.FloatR4TypeNode);
//    public static Sprite FloatR5TypeNode= GetSprite(SpriteDefine.FloatR5TypeNode);
//    public static Sprite FloatR6TypeNode= GetSprite(SpriteDefine.FloatR6TypeNode);
//    public static Sprite FloatR7TypeNode= GetSprite(SpriteDefine.FloatR7TypeNode);
//    public static Sprite FloatR8TypeNode= GetSprite(SpriteDefine.FloatR8TypeNode);
//    public static Sprite EnumRTypeNode= GetSprite(SpriteDefine.EnumRTypeNode);
//    public static Sprite EnumR1TypeNode= GetSprite(SpriteDefine.EnumR1TypeNode);
//    public static Sprite EnumR2TypeNode= GetSprite(SpriteDefine.EnumR2TypeNode);
//    public static Sprite EnumR3TypeNode= GetSprite(SpriteDefine.EnumR3TypeNode);
//    public static Sprite EnumR4TypeNode= GetSprite(SpriteDefine.EnumR4TypeNode);
//    public static Sprite EnumR5TypeNode= GetSprite(SpriteDefine.EnumR5TypeNode);
//    public static Sprite EnumR6TypeNode= GetSprite(SpriteDefine.EnumR6TypeNode);
//    public static Sprite EnumR7TypeNode= GetSprite(SpriteDefine.EnumR7TypeNode);
//    public static Sprite EnumR8TypeNode= GetSprite(SpriteDefine.EnumR8TypeNode);
//    public static Sprite EnumR9TypeNode= GetSprite(SpriteDefine.EnumR9TypeNode);
}

public static class BlockGraphicGetter
{
    public static IParamGetterCompotent GetGetterCompotent(GetterDefine key)
    {
        return GraphicHelper.Graphic.InstanceParamGetter(key.ToString());
    }
//    public static IParamGetterCompotent BoolRTypeNode=GetGetterCompotent(GetterDefine.BoolRTypeNode);
//    public static IParamGetterCompotent BoolR2TypeNode=GetGetterCompotent(GetterDefine.BoolR2TypeNode);
//    public static IParamGetterCompotent BoolR3TypeNode=GetGetterCompotent(GetterDefine.BoolR3TypeNode);
//    public static IParamGetterCompotent BoolR4TypeNode=GetGetterCompotent(GetterDefine.BoolR4TypeNode);
//    public static IParamGetterCompotent BoolR5TypeNode=GetGetterCompotent(GetterDefine.BoolR5TypeNode);
//    public static IParamGetterCompotent BoolR6TypeNode=GetGetterCompotent(GetterDefine.BoolR6TypeNode);
//    public static IParamGetterCompotent BoolR7TypeNode=GetGetterCompotent(GetterDefine.BoolR7TypeNode);
//    public static IParamGetterCompotent BoolR8TypeNode=GetGetterCompotent(GetterDefine.BoolR8TypeNode);
//    public static IParamGetterCompotent BoolR9TypeNode=GetGetterCompotent(GetterDefine.BoolR9TypeNode);
//    public static IParamGetterCompotent IntRTypeNode=GetGetterCompotent(GetterDefine.IntRTypeNode);
//    public static IParamGetterCompotent IntR1TypeNode=GetGetterCompotent(GetterDefine.IntR1TypeNode);
//    public static IParamGetterCompotent IntR2TypeNode=GetGetterCompotent(GetterDefine.IntR2TypeNode);
//    public static IParamGetterCompotent IntR3TypeNode=GetGetterCompotent(GetterDefine.IntR3TypeNode);
//    public static IParamGetterCompotent IntR4TypeNode=GetGetterCompotent(GetterDefine.IntR4TypeNode);
//    public static IParamGetterCompotent IntR5TypeNode=GetGetterCompotent(GetterDefine.IntR5TypeNode);
//    public static IParamGetterCompotent IntR6TypeNode=GetGetterCompotent(GetterDefine.IntR6TypeNode);
//    public static IParamGetterCompotent IntR7TypeNode=GetGetterCompotent(GetterDefine.IntR7TypeNode);
//    public static IParamGetterCompotent IntR8TypeNode=GetGetterCompotent(GetterDefine.IntR8TypeNode);
//    public static IParamGetterCompotent IntR9TypeNode=GetGetterCompotent(GetterDefine.IntR9TypeNode);
//    public static IParamGetterCompotent StringRTypeNode=GetGetterCompotent(GetterDefine.StringRTypeNode);
//    public static IParamGetterCompotent StringR1TypeNode=GetGetterCompotent(GetterDefine.StringR1TypeNode);
//    public static IParamGetterCompotent StringR2TypeNode=GetGetterCompotent(GetterDefine.StringR2TypeNode);
//    public static IParamGetterCompotent StringR3TypeNode=GetGetterCompotent(GetterDefine.StringR3TypeNode);
//    public static IParamGetterCompotent StringR4TypeNode=GetGetterCompotent(GetterDefine.StringR4TypeNode);
//    public static IParamGetterCompotent StringR5TypeNode=GetGetterCompotent(GetterDefine.StringR5TypeNode);
//    public static IParamGetterCompotent StringR6TypeNode=GetGetterCompotent(GetterDefine.StringR6TypeNode);
//    public static IParamGetterCompotent StringR7TypeNode=GetGetterCompotent(GetterDefine.StringR7TypeNode);
//    public static IParamGetterCompotent StringR8TypeNode=GetGetterCompotent(GetterDefine.StringR8TypeNode);
//    public static IParamGetterCompotent StringR9TypeNode=GetGetterCompotent(GetterDefine.StringR9TypeNode);
//    public static IParamGetterCompotent FloatRTypeNode=GetGetterCompotent(GetterDefine.FloatRTypeNode);
//    public static IParamGetterCompotent FloatR1TypeNode=GetGetterCompotent(GetterDefine.FloatR1TypeNode);
//    public static IParamGetterCompotent FloatR2TypeNode=GetGetterCompotent(GetterDefine.FloatR2TypeNode);
//    public static IParamGetterCompotent FloatR3TypeNode=GetGetterCompotent(GetterDefine.FloatR3TypeNode);
//    public static IParamGetterCompotent FloatR4TypeNode=GetGetterCompotent(GetterDefine.FloatR4TypeNode);
//    public static IParamGetterCompotent FloatR5TypeNode=GetGetterCompotent(GetterDefine.FloatR5TypeNode);
//    public static IParamGetterCompotent FloatR6TypeNode=GetGetterCompotent(GetterDefine.FloatR6TypeNode);
//    public static IParamGetterCompotent FloatR7TypeNode=GetGetterCompotent(GetterDefine.FloatR7TypeNode);
//    public static IParamGetterCompotent FloatR8TypeNode=GetGetterCompotent(GetterDefine.FloatR8TypeNode);
//    public static IParamGetterCompotent FloatR9TypeNode=GetGetterCompotent(GetterDefine.FloatR9TypeNode);
//    public static IParamGetterCompotent EnumRTypeNode=GetGetterCompotent(GetterDefine.EnumRTypeNode);
//    public static IParamGetterCompotent EnumR1TypeNode=GetGetterCompotent(GetterDefine.EnumR1TypeNode);
//    public static IParamGetterCompotent EnumR2TypeNode=GetGetterCompotent(GetterDefine.EnumR2TypeNode);
//    public static IParamGetterCompotent EnumR3TypeNode=GetGetterCompotent(GetterDefine.EnumR3TypeNode);
//    public static IParamGetterCompotent EnumR4TypeNode=GetGetterCompotent(GetterDefine.EnumR4TypeNode);
//    public static IParamGetterCompotent EnumR5TypeNode=GetGetterCompotent(GetterDefine.EnumR5TypeNode);
//    public static IParamGetterCompotent EnumR6TypeNode=GetGetterCompotent(GetterDefine.EnumR6TypeNode);
//    public static IParamGetterCompotent EnumR7TypeNode=GetGetterCompotent(GetterDefine.EnumR7TypeNode);
//    public static IParamGetterCompotent EnumR8TypeNode=GetGetterCompotent(GetterDefine.EnumR8TypeNode);
//    public static IParamGetterCompotent EnumR9TypeNode=GetGetterCompotent(GetterDefine.EnumR9TypeNode);
}

public static class BlockGraphicSetter
{
    public static IParamSetterPanel GetPanel(SetterDefine key)
    {
        return GraphicHelper.Graphic.GetParamSetterPanel(key.ToString());
    }
}

public static class BlockGraphicFont
{
    public static Font GetFont()
    {
        return GraphicHelper.Graphic.GetFont();
    }
}

public static class BlockSound
{
    static AudioClip GetClip(SoundDefine key)
    {
        return GraphicHelper.Graphic.GetClip(key.ToString());
    }

    public static AudioClip SlotAudio = GetClip(SoundDefine.SlotAudio);
    public static AudioClip DeslotAudio = GetClip(SoundDefine.DeslotAudio);
    public static AudioClip PackAudio = GetClip(SoundDefine.PackAudio);
    public static AudioClip DepackAudio = GetClip(SoundDefine.DepackAudio);
}